package com.example.shoppingdemo.nslcommodity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.shoppingdemo.R;
import com.example.shoppingdemo.nslcommodity.javabean.AdapterModel;
import com.example.shoppingdemo.nslcommodity.javabean.PayModel;
import com.example.shoppingdemo.nslcommodity.javabean.ShopModel;

import java.util.List;
/**
 * 待付款列表的Adapter
 */
public class PaymentAdapter extends RecyclerView.Adapter<PaymentAdapter.PaymentHolder>{
    private onPaymentParticulars listenter;
    private Context context;
    private List<PayModel> adapterModels;

    public PaymentAdapter(Context context) {
        this.context = context;
    }

    public void setListenter(onPaymentParticulars listenter) {
        this.listenter = listenter;
    }

    public void setAdapterModels(List<PayModel> adapterModels) {
        this.adapterModels = adapterModels;
    }

    @NonNull
    @Override
    public PaymentHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View  baseView = LayoutInflater.from(parent.getContext()).inflate(R.layout.payment_item, parent, false);
        PaymentHolder holder=new PaymentHolder(baseView);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull PaymentAdapter.PaymentHolder holder, int position) {
        holder.smoney.setText("实付款 ￥"+adapterModels.get(position).getSmoney());
        holder.numder.setText("订单编号："+adapterModels.get(position).getNumder());
        List<ShopModel> shopModelList=adapterModels.get(position).getShopModelList();
        ShopAdapter shopAdapter=new ShopAdapter(shopModelList);

        holder.recyclerView.setAdapter(shopAdapter);
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext()));
    }

    @Override
    public int getItemCount() {
        return null==adapterModels?0:adapterModels.size();
    }

    class PaymentHolder extends RecyclerView.ViewHolder{
        RecyclerView recyclerView;
        TextView smoney;
        LinearLayout layout;
        TextView numder;
        public PaymentHolder(@NonNull View itemView) {
            super(itemView);
            layout=itemView.findViewById(R.id.layout_payment_item);
            smoney=itemView.findViewById(R.id.text_order_payment_money);
            recyclerView=itemView.findViewById(R.id.item_payment_recycler);
            numder=itemView.findViewById(R.id.text_item_payment_numder);
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listenter.onPaymentResult(PaymentHolder.this.getAdapterPosition());
                }
            });
        }
    }
    public interface onPaymentParticulars{
        void onPaymentResult(int position);
    }
}
